package com.hwbsite.hwbback.controller;


import com.hwbsite.hwbback.entity.UserDTO;
import com.hwbsite.hwbback.service.UserService;
import com.hwbsite.hwbback.utils.DhRes;
import com.hwbsite.hwbback.utils.UserTokenUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

@RestController
@RequestMapping("/tt/user")
@AllArgsConstructor
public class UserController {

    private final UserService userService;


    @PostMapping("/create")
    public DhRes register(@Valid @RequestBody UserDTO userDTO){
        return userService.register(userDTO);
    }

    @PostMapping("/forget")
    public DhRes forget(@Valid @RequestBody UserDTO userDTO){
        return userService.forget(userDTO);
    }

    @PostMapping("/userId")
    public DhRes userId(){
        return DhRes.success(UserTokenUtils.getUserId());
    }

    @PostMapping("/edit")
    public DhRes userEdit(@RequestBody UserDTO userDTO){
        return userService.userEdit(userDTO);
    }

    @GetMapping("/info")
    public DhRes userInfo(String userId){
        return userService.userInfo(userId);
    }
}
